﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpriteManager : MonoBehaviour
{
    public static Dictionary<string,Sprite> _speites = new Dictionary<string, Sprite>();

    public List<Sprite> Sprites;


    private void OnValidate()
    {
        if (Sprites !=null)
        {
            if(_speites.Count == 0)
                _speites.Clear();
            if (Sprites.Count != _speites.Count)
            {
                _speites.Clear();
                foreach (var s in Sprites)
                {
                    Debug.Log("s"+s.name);
                    if (!_speites.ContainsKey(s.name))
                    {
                        _speites.Add(s.name,s);
                    }
                }
            }
        }
    }

    /// <summary>
    /// 获取Sprite
    /// </summary>
    /// <param name="roadType"></param>
    /// <returns></returns>
    public static Sprite TryGetSpriteByName(RoadType roadType)
    {
        Sprite sprite = null;
        if (_speites.ContainsKey(roadType.ToString()))
        {
            _speites.TryGetValue(roadType.ToString(), out sprite);
        }
        return sprite;
    }
}
